package com.hs.dao.DaoImpl;

import com.hs.dao.UserDao;
import com.hs.entity.User;
import com.hs.util.JDBCDruidUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {

    @Override
    public User selectAllByUsernameAndPwd(String username, String password) {
        String sql = "select * from user where username=? and password=?";
        Object obj[] = {username,password};
        User user = null;
        ResultSet res = JDBCDruidUtil.query(sql, obj);
        try {
            if (res.next()){
                int id = res.getInt(1);
                String name = res.getString(2);
                String pwd = res.getString(3);
                user=new User(id,name,pwd);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return user;
    }
}
